package com.hmall.search.listeners;

import com.hmall.search.service.SearchService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ItemStatusListen {
    @Autowired
    SearchService searchService;

    //商品上架，新增es数据同步
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "up.queue"),
            exchange = @Exchange(name = "item.topic"),
            key = {"item.up"}

    ))
    public void listenUpQueue(Long id){
        searchService.saveStatus(id);
    }

    //商品下架，删除es数据同步
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "down.queue"),
            exchange = @Exchange(name = "item.topic"),
            key = {"item.down"}

    ))
    public void listenDownQueue(Long id){
        searchService.deleteStatus(id);
    }
}
